package com.wx.chapter11.homework.homework06;

/**
 * @Author : 佩萁
 * Description :
 * @Create : 2023/6/14 - 15:32
 */
public class Person {
    private String name;//使用交通工具者的名字
    private Vehicles vehicles;//交通方式

    //过河
    public void passRiver() {
/*        if (vehicles == null) {
            vehicles = Transportation.getBoat();
            vehicles.work();
        } else if (vehicles instanceof Horse) {
            vehicles = Transportation.getBoat();
            vehicles.work();
        } else {
            vehicles.work();
        }*/
        if (!(vehicles instanceof Boat)) {
            vehicles = Transportation.getBoat();
        }
        vehicles.work();
    }

    //一般赶路
    public void common() {
/*        if (vehicles == null) {
            vehicles = Transportation.getHorse();
            vehicles.work();
        } else if (vehicles instanceof Boat) {
            vehicles = Transportation.getHorse();
            vehicles.work();
        } else {
            vehicles.work();
        }*/
        if (!(vehicles instanceof Horse)) {
            vehicles = Transportation.getHorse();
        }
        vehicles.work();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Person(String name, Vehicles vehicles) {
        this.name = name;
        this.vehicles = vehicles;
    }
}
